﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Midi;
using AutomaTones.Model.Automaton_Model;
using Microsoft.Pex.Framework;

namespace AutomaTones.Model.MIDI.Mappers
{
    [PexClass]
    partial class SampleTranslator : IMapper
    {
        private readonly List<NoteOut> _notes = new List<NoteOut>();
        int counter = 0;

        [PexMethod]
        public List<NoteOut> Translate(State[,] grid)
        {
            Random random = new Random();
            _notes.Clear();
            if (counter > 12) {
                for (int x = 0; x < grid.GetLength(0); x++)
                    for (int y = 0; y < grid.GetLength(1); y++)
                        if (grid[x, y].CurrentState > 0)
                        {
                            if (grid[x, y].CurrentState == 1)
                            {
                                _notes.Add(new NoteOut(Pitch.G0, random.Next(128)));
                                break;
                            }
                            if (grid[x, y].CurrentState == 3)
                            {
                                _notes.Add(new NoteOut(Pitch.G0, random.Next(128)));
                                break;
                            }
                            if (grid[x, y].CurrentState == 5)
                            {
                                _notes.Add(new NoteOut(Pitch.G0, random.Next(128)));
                                break;
                            }
                        }
            }
            counter++;
            if (counter == 15) {
                counter = 0;
                _notes.Add(new NoteOut(Pitch.A3, 0, 30, random.Next(128)));
            }
            return _notes;
        }
    }
}
